<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>Hello Cangjie!</div>
    <p></p>
    <script>
        let xhr = new XMLHttpRequest()
        xhr.open("POST", "/testApi", true)
        xhr.onreadystatechange = () => {
            if(xhr.readyState == 4 && xhr.status == 200){
                let res = JSON.parse(xhr.responseText)
                // 接受到后端 json 数据并插入到 dom 
                document.body.innerHTML += `<div>${res.msg}</div>`
            }
        }
        xhr.send(JSON.stringify({
            name: "chen",
            age: 999,
        }))
    </script>
</body>
</html>